<?php
require_once "common.php";

$fname = basename($_FILES['file0']['name']);
$pathinfo = pathinfo($fname);
$ext = $pathinfo['extension'];

$pid = uniqid();
$basedir = dirname(__FILE__);
$uploadfile = $basedir . fs_location($pid, $ext);
$uploaddir = dirname($uploadfile);
if(!file_exists($uploaddir)){
    mkdir($uploaddir, 0776, true);
}

pic_insert($pid, $ext);
if (move_uploaded_file($_FILES['file0']['tmp_name'], $uploadfile)) {

} else {
  exit('file upload error');
}

if ($_GET['redirect']){
    $refurl = "mark.html?pid=$pid";
    Header("Location:" .$refurl );
}else{
    echo(pic_info($pid));
}

?> 

